<template>
  <div id="m-pl-pager">
    <!--分页部分-->
    <div class="u-page" v-if="pages < 10">
      <a href="javascript:void(0)" class="zbtn zprv"
         :class="pageNum === 1 ? 'js-disabled' : ''"
         @click="getDataWithPageNum(pageNum-1)">上一页</a>

      <a href="javascript:void(0)"
         v-for="(item, index) in pages"
         class="zpgi" :class="item === pageNum ? 'js-selected' : ''"
         @click="getDataWithPageNum(item)">{{item}}</a>

      <a href="javascript:void(0)"
         class="zbtn znxt" :class="pageNum === pages ? 'js-disabled' : ''"
         @click="getDataWithPageNum(pageNum+1)">下一页</a>
    </div>

    <div class="u-page" v-if="pages >= 10 && pageNum <= 5">
      <a href="javascript:void(0)" class="zbtn zprv"
         :class="pageNum === 1 ? 'js-disabled' : ''"
         @click="getDataWithPageNum(pageNum-1)">上一页</a>

      <a href="javascript:void(0)"
         v-for="(item, index) in 8"
         class="zpgi" :class="item === pageNum ? 'js-selected' : ''"
         @click="getDataWithPageNum(item)">{{item}}</a>
      <span class="zdot">...</span>

      <a href="javascript:void(0)" class="zpgi">{{pages}}</a>

      <a href="javascript:void(0)"
         class="zbtn znxt" :class="pageNum === pages ? 'js-disabled' : ''"
         @click="getDataWithPageNum(pageNum+1)">下一页</a>
    </div>

    <div class="u-page" v-if="pages >= 10 && pageNum > 5 && (pages - pageNum) > 5">
      <a href="javascript:void(0)" class="zbtn zprv"
         :class="pageNum === 1 ? 'js-disabled' : ''" @click="getDataWithPageNum(pageNum-1)">上一页</a>

      <a href="javascript:void(0)" class="zpgi" @click="getDataWithPageNum(1)">1</a>
      <span class="zdot">...</span>
      <a href="javascript:void(0)"
         v-for="(item, index) in [pageNum-3, pageNum-2, pageNum-1, pageNum, pageNum+1, pageNum+2, pageNum+3]"
         class="zpgi" :class="item === pageNum ? 'js-selected' : ''" @click="getDataWithPageNum(item)">{{item}}</a>
      <span class="zdot">...</span>
      <a href="javascript:void(0)" class="zpgi" @click="getDataWithPageNum(pages)">{{pages}}</a>

      <a href="javascript:void(0)"
         class="zbtn znxt" :class="pageNum === pages ? 'js-disabled' : ''"
         @click="getDataWithPageNum(pageNum+1)">下一页</a>
    </div>

    <div class="u-page" v-if="pages >= 10 && (pages - pageNum) <= 5">
      <a href="javascript:void(0)" class="zbtn zprv"
         :class="pageNum === 1 ? 'js-disabled' : ''"
         @click="getDataWithPageNum(pageNum-1)">上一页</a>

      <span class="zdot">...</span>

      <a href="javascript:void(0)"
         v-for="(item, index) in 8"
         class="zpgi" :class="pages-(8-item) === pageNum ? 'js-selected' : ''"
         @click="getDataWithPageNum(pages-(8-item))">{{pages-(8-item)}}</a>

      <a href="javascript:void(0)"
         class="zbtn znxt" :class="pageNum === pages ? 'js-disabled' : ''"
         @click="getDataWithPageNum(pageNum+1)">下一页</a>
    </div>
  </div>
</template>

<script>
  export default {
    name: 'pagination',
    props: {
      pageNum: {
        type: Number
      },
      pages: {
        type: Number
      },
      getDataWithPageNum: {}

    },
    data() {
      return {

      }
    },
    mounted() {

    },
    methods: {


    }

  }
</script>

<style scoped>

  div.u-page {
    margin: 20px 0;
    text-align: center;
  }

  div.u-page .zbtn {
    width: 69px;
    height: 24px;
    line-height: 24px;
    color: #333;
    text-align: left;
    padding: 0;
  }

  div.u-page .zbtn, div.u-page .zpgi {
    margin: 0 1px 0 2px;
    display: inline-block;
    border: 1px solid #ccc;
    border-radius: 2px;
    vertical-align: middle;
  }

  div.u-page a, div.u-page a.js-selected, div.u-page a.znxt.js-disabled, div.u-page a.zprv.js-disabled {
    background: url(../image/button.png) no-repeat 0 9999px;
  }

  div.u-page .zpgi {
    height: 22px;
    padding: 0 8px;
    background-color: #fff;
    line-height: 22px;
  }

  div.u-page .zpgi:hover {
    border-color: #666;
  }

  div.u-page a:hover {
    text-decoration: none;
  }

  div.u-page a.zprv.js-disabled, div.u-page a.zprv.js-disabled:hover {
    background-position: 0 -620px;
    color: #cacaca;
    cursor: default;
    pointer-events: none;
  }

  div.u-page a.znxt.js-disabled, div.u-page a.znxt.js-disabled:hover {
    background-position: -75px -620px;
    color: #cacaca;
    cursor: default;
    pointer-events: none;
  }

  div.u-page a.js-selected, div.u-page a.js-selected:hover {
    background-position: 0 -650px;
    border-color: #A2161B;
    color: #fff;
    cursor: default;
  }

  div.u-page .zbtn, div.u-page .zpgi {
    margin: 0 1px 0 2px;
    display: inline-block;
    border: 1px solid #ccc;
    border-radius: 2px;
    vertical-align: middle;
  }

  div.u-page .zbtn {
    width: 69px;
    height: 24px;
    line-height: 24px;
    color: #333;
    text-align: left;
    padding: 0;
  }

  div.u-page .zprv {
    width: 47px;
    padding-left: 22px;
    background-position: 0 -560px;
  }

  div.u-page .znxt {
    width: 57px;
    padding-left: 12px;
    background-position: -75px -560px;
  }
</style>
